﻿using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using Serilog;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WLYT.Application.Interfaces;
using WLYT.Common;
using WLYT.Core;
using WLYT.Domain.Entries;
using WLYT.Domain.Model;

namespace WLYT.Application.Services
{
    public class WarehouseService(IHttpWebService httpWebService) : IWarehouseService
    {
        public async Task<ApiResult> SendTask(SMTModel item)
        {
            ApiResult result = new();
            if (string.IsNullOrEmpty(item.IP)) return result;
            string url = $"http://{item.IP}:6789/slapi/SCRW.ashx";
            var param = new
            {
                AppId = "Wlyt-001",
                ApiName = "Wlyt.OutStock",
                AddDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                ParamData = item,
            };
            try
            {
                result = await httpWebService.HttpPostAsync<ApiResult>(url, param);
            }
            catch (Exception ex)
            {
                result.Code = 1;
                result.Message = ex.Message; 
            }
            return result;
        }
    }
}
